<?php
//  ----------------------------------------------------------------------- //
//                          SHORTCUTS FOR XOOPS 2                           //
//                  Copyright (c) 2005-2006 Instant Zero                     //
//                     <http://xoops.instant-zero.com/>                      //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify     //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation; either version 2 of the License, or        //
// (at your option) any later version.                                      //
//																		    //
// You may not change or alter any portion of this comment or credits       //
// of supporting developers from this source code or any supporting         //
// source code which is considered copyrighted (c) material of the          //
// original comment or credit authors.                                      //
// 																			//
// This program is distributed in the hope that it will be useful,          //
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
// GNU General Public License for more details.                             //
// 																			//
// You should have received a copy of the GNU General Public License        //
// along with this program; if not, write to the Free Software              //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------ //

include_once '../../../include/cp_header.php';
include_once XOOPS_ROOT_PATH.'/modules/shortcuts/include/functions.php';


xoops_cp_header();
// Get the module's options
$userscount=st_getmoduleoption('statsnumber');;
$enablerating=st_getmoduleoption('enablerating');
$savehits=st_getmoduleoption('savehits');

$shortcuts_handler =& xoops_getmodulehandler('shortcuts', 'shortcuts');

printf("<h1>%s</h1>\n",_AM_SHORTCUT_STATS);

// Total number of shortcuts
printf('<br /><h4>'._AM_SHORTCUT_STATS0.'</h4>',$shortcuts_handler->getCount());
if($savehits) {
	printf("<div style='text-align: center;'><b>"._AM_SHORTCUT_STATS1.'</b><br />',$userscount);
	echo "<table border='1' width='100%'><tr class='bg3'>";
	echo "<td align='center'>"._AM_SHORTCUT_PAGE."</td>";
	echo "<td align='center'>"._AM_SHORTCUT_VISITS."</td>";
	echo "</tr>";
	$start = 0;
	$critere=new Criteria('1', '1','=');
	$critere->setLimit($userscount);
	$critere->setStart($start);
	$critere->setSort('hits');
	$critere->setOrder('DESC');
	$tblshortcuts = $shortcuts_handler->getObjects($critere);
	foreach($tblshortcuts as $one_shortcut) {
		$url = XOOPS_URL.$one_shortcut->getVar('url');
		printf("<tr><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n",$url,$url,$one_shortcut->getVar('hits'));
	}
	echo "</table></div><br />";
}



// Most bookmarked urls
printf("<div style='text-align: center;'><b>"._AM_SHORTCUT_STATS3.'</b><br />',$userscount);
echo "<table border='1' width='100%'><tr class='bg3'><td align='center'>"._AM_SHORTCUT_PAGE."</td><td align='center'>"._AM_SHORTCUT_COUNT."</td></tr>";
$critere=new Criteria('1', '1','=');
$critere->setLimit($userscount);
$critere->setStart($start);
$critere->setSort('cpt');
$critere->setOrder('DESC');
$critere->setGroupby('url');
$tblshortcuts = $shortcuts_handler->getObjects2('count(shortcutid) as cpt, url as lib',$critere);
foreach($tblshortcuts as $one_shortcut) {
	$url = XOOPS_URL.$one_shortcut['lib'];
	printf("<tr><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n",$url,$url,$one_shortcut['cpt']);
}
echo "</table></div><br />";



// Best rated pages
printf("<div style='text-align: center;'><b>"._AM_SHORTCUT_STATS2.'</b><br />',$userscount);
echo "<table border='1' width='100%'><tr class='bg3'><td align='center'>"._AM_SHORTCUT_PAGE."</td><td align='center'>"._AM_SHORTCUT_VOTE."</td></tr>";
$critere=new Criteria('1', '1','=');
$critere->setLimit($userscount);
$critere->setStart($start);
$critere->setSort('rating');
$critere->setOrder('DESC');
$tblshortcuts = $shortcuts_handler->getObjects($critere);
foreach($tblshortcuts as $one_shortcut) {
	$url = XOOPS_URL.$one_shortcut->getVar('url');
	printf("<tr><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n",$url,$url,$one_shortcut->getVar('rating'));
}
echo "</table></div><br />";


// Users Top
printf("<div style='text-align: center;'><b>"._AM_SHORTCUT_STATS4.'</b><br />',$userscount);
echo "<table border='1' width='100%'><tr class='bg3'><td align='center'>"._AM_SHORTCUT_USER."</td><td align='center'>"._AM_SHORTCUT_USER_COUNT."</td></tr>";
$critere=new Criteria('1', '1','=');
$critere->setLimit($userscount);
$critere->setStart($start);
$critere->setSort('cpt');
$critere->setOrder('DESC');
$critere->setGroupby('uid');
$tmpshortcut = $shortcuts_handler->create();
$tblshortcuts = $shortcuts_handler->getObjects2('count(uid) as cpt, uid as lib',$critere);
foreach($tblshortcuts as $one_shortcut) {
	$url = XOOPS_URL.$one_shortcut['lib'];
	printf("<tr><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n",$url,$tmpshortcut->uname($one_shortcut['lib']),$one_shortcut['cpt']);
}
echo "</table></div><br />";


// Latest shortcuts
printf("<div style='text-align: center;'><b>"._AM_SHORTCUT_LATEST_SHORTCUTS.'</b><br />',$userscount);
echo "<table border='1' width='100%'><tr class='bg3'><td align='center'>"._AM_SHORTCUT_USER."</td><td align='center'>"._AM_SHORTCUT_PAGE."</td><td>"._AM_SHORTCUT_DATE."</td></tr>";
$critere=new Criteria('1', '1','=');
$critere->setLimit($userscount);
$critere->setStart($start);
$critere->setSort('date');
$critere->setOrder('DESC');
$tblshortcuts = $shortcuts_handler->getObjects($critere);
foreach($tblshortcuts as $one_shortcut) {
	$url2 = XOOPS_URL.$one_shortcut->getVar('url');
	$url=XOOPS_URL."/userinfo.php?uid=".$one_shortcut->getVar('uid');
	$date=formatTimestamp($one_shortcut->getVar('date'));
	printf("<tr><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='center'>%s</td></tr>\n",$url,$one_shortcut->uname(),$url2,$url2,$date);
}
echo "</table></div><br />";


echo "<br /><br /><table border='0' width='100%' align='center'><tr><td align='center'><a href='http://xoops.instant-zero.com' target='_blank'><img src='../images/instantzero.gif'></a></td></tr></table>";
xoops_cp_footer();
?>